package com.hq.ims.data.vo;

import com.hq.ims.data.config.verification.VdAdd;
import com.hq.ims.data.config.verification.VdEdit;
import com.hq.ims.data.entity.PermissionMenu;
import com.hq.ims.data.entityenum.EnumMenuOwnType;
import com.hq.utils.util.ListUtils;
import com.hq.utils.util.StringUtils;
import com.hq.web.penum.EnumMenuType;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.mapstruct.Mapper;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;


/**
 * @since 20240920
 */
@Mapper
public interface PermissionMenuMapstruct {

    PermissionMenuMapstruct INSTANCE = Mappers.getMapper(PermissionMenuMapstruct.class);

    //-------------------------------- 转换VO类 --------------------------------

    @Mappings({
    })
    PermissionMenuVo toPermissionMenuVo(PermissionMenu source);

    default List<PermissionMenuVo> toPermissionMenuVoList(List<PermissionMenu> source) {
        if (source == null) {
            return ListUtils.newEmptyList();
        }
        return source.stream().map(this::toPermissionMenuVo).collect(Collectors.toList());
    }

    @Mappings({
    })
    PermissionMenuVo toPermissionMenuTreeVo(PermissionMenu source);

    default List<PermissionMenuVo> toPermissionMenuTreeVoList(List<PermissionMenu> source) {
        if (source == null) {
            return ListUtils.newEmptyList();
        }
        return source.stream().map(this::toPermissionMenuTreeVo).collect(Collectors.toList());
    }

    //-------------------------------- 以下为自定义类[输出对象] --------------------------------

    @ApiModel(value = "原始对象的扩展类")
    @Data
    class PermissionMenuVo extends PermissionMenu {

    }

    @ApiModel(value = "菜单树结构")
    @Data
    class PermissionMenuTreeVo extends PermissionMenu {

        @ApiModelProperty("子菜单")
        private List<PermissionMenuTreeVo> childrenMenuList = new ArrayList<>();

        @ApiModelProperty("子按钮")
        private List<PermissionMenuTreeVo> childrenButtonList = new ArrayList<>();

    }


    //-------------------------------- 以下为自定义类[输入对象] --------------------------------

    @ApiModel(value = "搜索VO")
    @Data
    class PageSearchVo {

    }

    @ApiModel(value = "添加和修改对象")
    @Data
    class SaveVo {

        @NotBlank(message = "菜单ID不能为空", groups = {VdEdit.class})
        private String permissionMenuId;

        @NotBlank(message = "菜单名称不能为空", groups = {VdAdd.class, VdEdit.class})
        private String menuName;

        @NotBlank(message = "父ID为空", groups = {VdAdd.class, VdEdit.class})
        private String parentId;

        private String pageKey = StringUtils.EMPTY;

        private String appPageKey = StringUtils.EMPTY;

        private String icon = StringUtils.EMPTY;

        private String pageParam = StringUtils.EMPTY;

        private String remark = StringUtils.EMPTY;

        @NotNull(message = "菜单类型不能为空", groups = {VdAdd.class, VdEdit.class})
        private EnumMenuType type;

        @NotNull(message = "菜单所属类型不能为空", groups = {VdAddRootNode.class})
        private EnumMenuOwnType ownType;

        @NotNull(message = "是否显示", groups = {VdAdd.class, VdEdit.class})
        public Boolean isShow;

        private Integer orderNumber = 0;

        private String routePath;

        private String routeName;

        private String componentPath;


    }

    //-------------------------------- springboot验证标识 --------------------------------
    interface VdAddRootNode {
    }

}
